package com.atguigu.gmall.item.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.service.SkuDetailService;
import com.atguigu.gmall.item.vo.SkuDetailVo;
import com.atguigu.gmall.product.entity.BaseCategory1;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

// 远程调用时返回JSON
@Api("商品详情的rpc")
@RequestMapping("/api/inner/rpc/item")
@RestController
public class SkuDetailRpcController {

    @Autowired
    SkuDetailService skuDetailService;
    // 方法支持高并发
    @GetMapping("/sku/detail/{skuId}") //调用item
    public Result<SkuDetailVo> getSkuDetailsBySkuId(@PathVariable("skuId") Long skuId){
        // 查询商品详情要用的数据
        SkuDetailVo skuDetailVo = skuDetailService.getSkuDetailData(skuId);
        // 增加商品热度
        skuDetailService.autoIncrementHotScore(skuId);
        return Result.ok(skuDetailVo);
    }


}
